//
//  DetailsViewController.m
//  Againstpoor
//
//  Created by 辰领科技 on 16/11/10.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "DetailsViewController.h"

@interface DetailsViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroview;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalInvestmentLabel;
@property (weak, nonatomic) IBOutlet UILabel *planningLabel;
@property (weak, nonatomic) IBOutlet UILabel *completeLabel;
@property (weak, nonatomic) IBOutlet UILabel *sourceLabel;
@property (weak, nonatomic) IBOutlet UILabel *situationLabel;
@property (weak, nonatomic) IBOutlet UILabel *labelOne;

@property (weak, nonatomic) IBOutlet UIView *detailView;
@property (weak, nonatomic) IBOutlet UILabel *natureLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;
@property (weak, nonatomic) IBOutlet UILabel *responsibilityLabel;
@property (weak, nonatomic) IBOutlet UILabel *constructioncontentLabel;
@property (weak, nonatomic) IBOutlet UILabel *CompletecontentLabel;
@property (weak, nonatomic) IBOutlet UILabel *sizeLabel;

@property (weak, nonatomic) IBOutlet UIView *viewTwo;
@property (weak, nonatomic) IBOutlet UILabel *noteLabel;


@end

@implementation DetailsViewController

-(void)viewWillAppear:(BOOL)animated    {
    [super viewWillAppear:animated];
    [self getprojectDetail];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.detailView];
    [self adaptiveViewLayout:self.viewTwo];
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 扶贫详情
- (void)getprojectDetail {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:_ID forKey:@"id"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_projectDetail withHttpType:@"POST" withTag:F_F_projectDetail];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==F_F_projectDetail) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            NSDictionary *dic = database[@"data"];
            
            _titleLabel.text = _titleStr;
            _totalInvestmentLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:dic[@"TOTAL_INVESTMENT"]]];
            _planningLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:dic[@"REPONS_PLANT"]]];
            _completeLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:dic[@"COMPLETE_ROUND"]]];
            _sourceLabel.text = [NSString stringWithFormat:@"财政专项扶贫资金 ￥%@万\n其他部门财政资金 ￥%@\n社会扶贫资金 ￥%@\n自筹资金 ￥%@万",[Common stringFromData:dic[@"SPECIAL_PRICE"]],[Common stringFromData:dic[@"OTHER_PRICE"]],[Common stringFromData:dic[@"SOCIAL_PRICE"]],[Common stringFromData:dic[@"SELF_PRICE"]]];
            _situationLabel.text = [NSString stringWithFormat:@"投资金额 %@万\n投资计划文号：%@%@",[Common stringFromData:dic[@"ISSUED_PRICE"]],[Common stringFromData:dic[@"plantName"]],[Common stringFromData:dic[@"plantNum"]]];
            
            NSString *_kind = [Common stringFromData:dic[@"KIND"]];
            if ([_kind isEqualToString:@"01"]) {
                _natureLabel.text = @"新建";
            } else if ([_kind isEqualToString:@"02"]) {
                _natureLabel.text = @"改建";
            } else if ([_kind isEqualToString:@"03"]) {
                _natureLabel.text = @"整修";
            } else if ([_kind isEqualToString:@"04"]) {
                _natureLabel.text = @"硬化";
            }
            _addressLabel.text = [NSString stringWithFormat:@"%@%@",[Common stringFromData:dic[@"AREA"]],[Common stringFromData:dic[@"COUNTRY"]]];
            _timeLabel.text = [Common stringFromData:dic[@"IMPLEMENT_TIME"]];
            NSString *_pressType = [Common stringFromData:dic[@"PRESS_TYPE"]];
            if ([_pressType isEqualToString:@"01"]) {
                _progressLabel.text = @"未开工";
            } else if ([_pressType isEqualToString:@"02"]) {
                _progressLabel.text = @"开工在建";
            } else if ([_pressType isEqualToString:@"03"]) {
                _progressLabel.text = @"已完成";
            } else if ([_pressType isEqualToString:@"04"]) {
                _progressLabel.text = @"已验收";
            }
            _responsibilityLabel.text = [Common stringFromData:dic[@"DEPARTMENT"]];
            self.constructioncontentLabel.text = [Common stringFromData:dic[@"PLANT_CONTENT"]];
            self.CompletecontentLabel.text = [Common stringFromData:dic[@"COMPLETE_CONTENT"]];
            _sizeLabel.text = [Common stringFromData:dic[@"REPONS_PLANT"]];
            CGFloat sizeLabelHight = _sizeLabel.frame.size.height/VerticalRatio();
            if (sizeLabelHight == 0) {
                sizeLabelHight = 17;
            }
            
//            _sourceLabel.text = @"财政专项扶贫资金 ￥200万\n其他部门财政资金 ￥0.0\n社会扶贫资金 ￥0.0\n自筹资金 ￥120万";
//            _situationLabel.text = @"投资金额 198万\n投资计划文号：石柱特产发[ 2015 ] 122号";
//            _sizeLabel.text = @"新发展无花果600亩、土鸡3万只、生猪1500头，改善贫困农户生产状况，落实贫困户到人到户扶持政策";
            
            [self.sourceLabel sizeToFit];
            [self.situationLabel sizeToFit];
            [self.sizeLabel sizeToFit];
            [self.noteLabel sizeToFit];
            
            _labelOne.frame = CGRectMake(8*VerticalRatio(), CGRectGetMaxY(_sourceLabel.frame)+5*VerticalRatio(), 135, 17);
            _situationLabel.frame = CGRectMake(129*VerticalRatio(), CGRectGetMaxY(_sourceLabel.frame)+5*VerticalRatio(), 180, _situationLabel.frame.size.height);
            _detailView.frame = CGRectMake(0, CGRectGetMaxY(_situationLabel.frame)+5*VerticalRatio(), 320*VerticalRatio(), _sizeLabel.frame.origin.y+(sizeLabelHight+5)*VerticalRatio());
            _viewTwo.frame = CGRectMake(0, CGRectGetMaxY(_detailView.frame), 320*VerticalRatio(), CGRectGetMaxY(_noteLabel.frame)+5*VerticalRatio());
            
            CGFloat hight = _viewTwo.frame.origin.y+_viewTwo.frame.size.height;
            if (hight <= 504*VerticalRatio()) {
                hight = 505*VerticalRatio();
            }
            self.scroview.contentSize = CGSizeMake(0, hight);

        } else {
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}

@end
